London | 26-ITP-May | Remi M. | Sprint 1 | Coursework Sprint 1#1322
London | 26-ITP-May | Remi M. | Sprint 1 | Coursework Sprint 1#1322remimarcelle wants to merge 12 commits into
Conversation
…sing it in console.log
|
Linked to issue: remimarcelle/My-Coursework-Planner#58 |
cjyuan
left a comment
There was a problem hiding this comment.
Codes look good. No change needed.
I just have a few questions to test your understanding. You can just respond directly in the inline comments.
| // Line 3 is updating the value of the count variable. The = operator is an | ||
| // assignment operator, which assigns the value on the right side | ||
| // (count + 1) to the variable on the left side (count). In this case, | ||
| // it takes the current value of count (which is 0), adds 1 to it, and then | ||
| // assigns the result (1) back to count. So after line 3 executes, count will | ||
| // have a new value of 1. No newline at end of file |
There was a problem hiding this comment.
Operation like count = count + 1 is very common in programming, and there is a programming term describing such operation.
Can you find out what one-word programming term describes the operation on line 3?
| // Math.floor()= rounds a number down to the nearest integer | ||
| // Math.random() = generates a random float number between 0 and 1 (not including 1) | ||
| // Math.random() * 100 = generates a random float number between 0 and 99.999... |
There was a problem hiding this comment.
Note: To describe a range of numbers, we can use the concise and precise interval notation:
[,]=> inclusion(,)=> exclusion
For example, [1, 10) means, all numbers between 1 and 10, including 1 but excluding 10.
| // Line 10: console.log() | ||
|
|
||
| // b) Run the code and identify the line where the error is coming from - why is this error occurring? How can you fix this problem? | ||
| // Line 5 has a SyntaxError - there is a missing comma between "," and "" in replaceAll(","" should be replaceAll(",", "") |
There was a problem hiding this comment.
In the function call .replaceAll(",", ""), there's a programming term for "," and "" (the values passed into the function). Could you find out what it's called?
| // 2. penceString.substring(0, penceString.length - 1): removes the trailing "p" by taking all characters except the last one -> "399" | ||
| // 3. paddedPenceNumberString = "399".padStart(3, "0"): ensures the string is at least 3 characters long, padding with "0" on the left if needed. "399" stays "399" but "5p" would become "005" | ||
| // 4. pounds = paddedPenceNumberString.substring(0, length - 2): takes everything except the last 2 digits, giving the pounds part -> "3" | ||
| // 5. pence = paddedPenceNumberString.substring(length - 2).padEnd(2, "0"): takes the last 2 digits for the pence -> "99". padEnd ensures it stays 2 digits e.g. "5" would become "50" |
There was a problem hiding this comment.
Could we expect this program to work as intended for any valid penceString if we deleted .padEnd(2, "0") from the code?
In other words, do we really need .padEnd(2, "0") in this script?
Learners, PR Template
Self checklist
Changelist
Completed all coursework for sprint 1